//
//  BYNetAPIClient.m
//  BTCBOX
//
//  Created by biyunkeji on 2017/11/29.
//  Copyright © 2017年 jianfengChen. All rights reserved.
//

#import "NetAPIClient.h"
#import "Config.h"

@implementation NetAPIClient

static NSString *_baseUrl = @"";
static AFSSLPinningMode _pinningMode = AFSSLPinningModeNone;

+ (instancetype)sharedClient {
    static NetAPIClient *_sharedClient = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        if ([HOST containsString:@"https"] && [NetAPIClient isHostAddress]) {
           
            AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModePublicKey];
            securityPolicy.allowInvalidCertificates = YES;
            _sharedClient = [[NetAPIClient alloc] initWithBaseURL:[NSURL URLWithString:HOST]];
            [securityPolicy setValidatesDomainName:YES];
            _sharedClient.securityPolicy = securityPolicy;
            
        } else {
        _sharedClient = [[NetAPIClient alloc] initWithBaseURL:[NSURL URLWithString:_baseUrl]];
        _sharedClient.securityPolicy = [AFSecurityPolicy policyWithPinningMode:_pinningMode];
        }
    });
    return _sharedClient;
}

+ (BOOL)isHostAddress {
    
    return YES;
    
}

+ (void)baseUrl:(NSString *)baseUrl {
    _baseUrl = baseUrl;
}

+ (void)policyWithPinningMode:(AFSSLPinningMode)pinningMode {
    _pinningMode = pinningMode;
}

@end
